package com.thinvent.nj.ais.controller.map;


import com.thinvent.nj.ais.entity.DictItem;
import com.thinvent.nj.ais.entity.Gcd;
import com.thinvent.nj.ais.service.BdService;
import com.thinvent.nj.ais.service.DictService;
import com.thinvent.nj.ais.service.GcdService;
import com.thinvent.nj.common.rest.ResponseEntity;
import com.thinvent.nj.common.util.CollectionUtil;
import com.thinvent.nj.common.util.MapperUtil;
import com.thinvent.nj.web.controller.BaseViewController;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.resource.ResourceUrlProvider;

import java.util.List;
import java.util.Map;

/**
 * @author yanyj
 * @date 2018-7-19
 */
@Controller
@RequestMapping(path = "/map/dzdt")
public class MapController extends BaseViewController {

    @Autowired
    private DictService dictService;

    // 标点service
    @Autowired
    private BdService bdService;

    // 观测点Service
    @Autowired
    private GcdService gcdService;

    @RequiresPermissions("map:view")
    @RequestMapping(method = RequestMethod.GET)
    public String toHtml() {
        return "map/mapList";
    }

    // 地图配置项
    @RequestMapping(path = "/setting", method = RequestMethod.GET)
    @ResponseBody
    public ResponseEntity findMapSetting() {
        // 从字典项里查询出地图的配置项
        List<DictItem> settingList = dictService.getItemsByGroupKey("MAPS");
        return ResponseEntity.ok(settingList);
    }


    // 流量观测点

    /**
     * 获取所有的流量观测点
     * @return
     */
    @RequestMapping(path = "/gcds", method = RequestMethod.GET)
    @ResponseBody
    public ResponseEntity findAllGcds() {

        List<Gcd> gcdList = gcdService.findList(null);
        String[] columns = {"id", "gcdmc", "qdjd", "qdwd", "zdjd", "zdwd"};

        return ResponseEntity.ok(CollectionUtil.toListMap(gcdList, columns));
    }

    /**
     * 获取单个的流量观测点信息
     * @return
     */
    @RequestMapping(path = "/gcds/{id}", method = RequestMethod.GET)
    @ResponseBody
    public ResponseEntity findGcdById(@PathVariable("id") String id) {

        return ResponseEntity.ok(gcdService.get(id));
    }

    /**
     * 保存所有的流量观测点
     * @return
     */
    @RequestMapping(path = "/gcds", method = RequestMethod.POST)
    @ResponseBody
    public ResponseEntity saveGcd(@RequestBody Map<String, Object> params) {


        Gcd target = new Gcd();
        MapperUtil.copy(params, target);
        String id = gcdService.insertReturnId(target);
        return ResponseEntity.ok(id);
    }


    // add by yanyj 20180801 start
    // 标点


    // add by yanyj 20180801 end
}
